<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        #box {
            height: 500px;
            width: 800px;
            border: 1px solid #c0c0c0;

            position: absolute;
            margin: 100px auto;
            left: 200px;

        }

        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
            height: 100%;
            width: 100%;
        }

        ul>li {
            height: 100%;
            width: 100%;
            position: absolute;
            font-size: 30px;
            text-align: center;

        }

        li:nth-child(1) {

            /*background-color: red;*/
        }

        li:nth-child(2) {
            /*background-color: yellow;*/
        }

        li:nth-child(3) {
            /*background-color: green;*/
        }

        li:nth-child(4) {
            /*background-color: #0094ff;*/
        }

        li:nth-child(5) {
            /*background-color: pink;*/
        }

        ol {
            list-style: none;
            width: 100%;
            margin-top: 5px;
        }

        ol>li {
            height: 100px;
            width: 146px;
            margin-left: 8px;
            float: left;
            text-align: center;
            border: 1px solid #999999;
        }

        ol>li img {
            height: 100px;
            width: 146px;
            float: left;
        }
    </style>
    <script src="./js/aniamte.js"></script>
</head>

<body>


    <div id="box">
        <ul id="ul">
            <li><a href="javascript:void(0)"><img src="images/slidepic1.jpg" alt="" /></a></li>
            <li><a href="javascript:void(0)"><img src="images/slidepic2.jpg" alt="" /></a></li>
            <li><a href="javascript:void(0)"><img src="images/slidepic3.jpg" alt="" /></a></li>
            <li><a href="javascript:void(0)"><img src="images/slidepic4.jpg" alt="" /></a></li>
            <li><a href="javascript:void(0)"><img src="images/slidepic5.jpg" alt="" /></a></li>
        </ul>

        <ol id="ol">
            <li><a href="javascript:void(0)"><img src="images/slidepic1.jpg" alt="" /></a></li>
            <li><a href="javascript:void(0)"><img src="images/slidepic2.jpg" alt="" /></a></li>
            <li><a href="javascript:void(0)"><img src="images/slidepic3.jpg" alt="" /></a></li>
            <li><a href="javascript:void(0)"><img src="images/slidepic4.jpg" alt="" /></a></li>
            <li><a href="javascript:void(0)"><img src="images/slidepic5.jpg" alt="" /></a></li>
        </ol>
    </div>
</body>

</html>
<script>

    class Swiper {
        constructor(ele) {
            this.el = document.querySelector(ele);
            this.oUpLis = this.el.children[0].children;
            this.oDownLis = this.el.children[1].children;
            this.imgIndex = 0;
            this.autoPlay();
            
            this.timer = setInterval(() => {
                this.imgIndex++;
                this.autoPlay();
            }, 1500)

            this.mouseHandler();
            this.clickHandler();
        }
        autoPlay() {
            if (this.imgIndex >= this.oUpLis.length) {
                this.imgIndex = 0;
            }
            Array.from(this.oUpLis).forEach((item, index) => {
                utils.animate(item, { opacity: this.imgIndex == index ? 1 : 0 });
                utils.animate(this.oDownLis[index], { opacity: this.imgIndex == index ? 1 : 0.3 });
            })
        }
        //把鼠标相关写到一起
        mouseHandler() {
            this.el.onmouseenter = () => {
                clearInterval(this.timer);
            }
            this.el.onmouseleave = () => {
                this.timer = setInterval(() => {
                    this.imgIndex++;
                    this.autoPlay();
                }, 1500)
            }
        }
        //点击相关
        clickHandler() {
            let self = this;
            Array.prototype.slice.call(this.oDownLis).forEach((item, index) => {
                item.onclick = function () {
                    self.imgIndex = index;
                    self.autoPlay();
                }
            })
        }
    }

    new Swiper("#box")

</script>